# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
from mongo_items import finance,key_words,finance_words

class SinaFinancePipeline(object):
    def process_item(self, item, spider):
        # finance_obj=finance(content=item['content'],content_href=item['content_href'])
        # finance_obj.save()
        hav_id=[]
        words_list=map(lambda x:(x.id,x.word),key_words.objects())
        for key,value in words_list:
            if value in item['content']:
                hav_id.append(key)
        if hav_id.__len__()>0:
            finance_obj=finance(title=item['title'],content_href=item['content_href'],spider_jod_id=item['jod_id']).save()
            finance_id=finance_obj.id
            for sub_id in hav_id:
                finance_words(key_words_id=sub_id,finance_id=finance_id).save()
        return item
